package com.fyzk.activity.lottery.jc.beidan;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

import com.tyjc.lottery.R;
import com.fyzk.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 2017/11/27.
 */

public class GuoGuanAdapter extends BaseAdapter {

    private Context context;
    private List<GuoGuanBean> guoGuanTypes = new ArrayList<>();
    private GuoGuan_Pop.OnGuoGuanItemClickListener listener;

    public GuoGuanAdapter(Context context, List<GuoGuanBean> guoGuanTypes, GuoGuan_Pop.OnGuoGuanItemClickListener listener) {
        this.context = context;
        this.guoGuanTypes = guoGuanTypes;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return guoGuanTypes.size();
    }

    @Override
    public Object getItem(int i) {
        return guoGuanTypes.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        final GuoGuanBean bean = guoGuanTypes.get(i);
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.popup_guoguan_item, null);
            holder.guoGuan_cb = view.findViewById(R.id.guoguan_item_cb);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.guoGuan_cb.setText(bean.typeName);
        holder.guoGuan_cb.setChecked(bean.isCheck);
        if (listener != null) {
            LogUtil.d("啊啊啊啊");
            listener.onGuoGuanItemClick(guoGuanTypes);
        } else {
            LogUtil.d("------------");
        }

        holder.guoGuan_cb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bean.isCheck = !bean.isCheck;
                if (listener != null) {
                    listener.onGuoGuanItemClick(guoGuanTypes);
                }
            }
        });
        return view;
    }

    public void setGuoGuanTypes(List<GuoGuanBean> guoGuanTypes) {
        this.guoGuanTypes = guoGuanTypes;
        this.notifyDataSetChanged();
    }

    class ViewHolder {
        CheckBox guoGuan_cb;
    }
}
